/* jshint esversion: 6 */
$(document).ready(function() {
    $('.verfCode').blur(function() {
        var cellPhoneNum = $('.cellPhoneNum').val();
        if (/^1[3|4|5|7|8]\d{9}$/.test(cellPhoneNum)) {
            $('.cellPhoneNum').css("border", "1px solid #5944C3");
            $('.submit').css("background", "#5944C3");
        } else {
            $('.cellPhoneNum').css("border", "1px solid rgba(0, 0, 0, .2)");
            $('.submit').css("background", "rgba(0, 0, 0, 0.35)");
        }
    });
    $('#password2Reset').blur(function() {
        let password = $('#passwordReset').val();
        let password2 = $('#password2Reset').val();
        if (password != password2) {
            $('.submit').css("background", "rgba(0, 0, 0, 0.35)");

            $('.modal-body').html('两次密码输入不一致!');
            $('.modal').modal('show');
        } else {
            $('.submit').css("background", "#5944C3");
        }
    });
    $('.captcha').on('click', getCaptcha);
    $('#getresetVerfCode').on('click', function() {
        try {
            getRegVerfCode("reset");
        } catch (error) {}
    });
    $('#resetSubmit1').on('click', function() {
        let phone = $('#resetpwdPhone').val();
        if (phone == '') {
            $('.modal-body').html('手机号不能为空!');
            $('.modal').modal('show');
            return;
        } else if (!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
            $('.modal-body').html('不是完整的11位手机号或者正确的手机号前七位!');
            $('.modal').modal('show');
            return false;
        }
        $('.stepItem').eq(1).addClass("active");
        $('.linerstep').eq(1).addClass("active");
        $('.firstPage').hide();
        $('.secondPage').show();
    });
    $('#resetSubmit2').on('click', function() {
        let phone = $('#resetpwdPhone').val();
        let smsCaptcha = $('#verfResetCode').val();
        console.log(smsCaptcha);
        let password = $('#passwordReset').val();
        let password2 = $('#password2Reset').val();

        if (password != password2) {
            $('.modal-body').html('两次密码输入不一致');
            $('.modal').modal('show');
        } else if (!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
            $('.modal-body').html('不是完整的11位手机号或者正确的手机号前七位!');
            $('.modal').modal('show');
            return false;
        }
        ajaxXHR('post', url + 'v1/account/rese', function(data) {
            $('.modal-body').html('重置密码成功!<a href="login.html">去登陆</a>');
            $('.modal').modal('show');
            console.log("重置密码成功!");
        }, {
            phone: phone,
            smsCaptcha: smsCaptcha,
            password: password
        });
    });
});